﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ForumDB
{

	enum Method
	{ 
		GET,
		ADD
	}; 
		public class UserFactory
		{
			private delegate Query Del(String message);

			private SortedDictionary<Method, SortedDictionary<String, Delegate>> _master;

			private SortedDictionary<String, Delegate> _addFactory;
			private SortedDictionary<String, Delegate> _getFactory;
			private VER3 db_forum;



			public UserFactory(VER3 db)
			{

				 _master = new SortedDictionary<Method, SortedDictionary<String, Delegate>>();

				_addFactory = new SortedDictionary<String, Delegate>();
				_getFactory = new SortedDictionary<String, Delegate>();
				db_forum = db;
				//init:
				initialGetMethods();
				//initialAddMethods
				//?$%
				//...
			}


			void initialGetMethods()
			{
				//?$%
				_getFactory.Add("Posts", (Del)getPosts);
				//_getFactory.Add("Threads", (Del)getThreads);
			}

			//************************************************************************************
			public Query getPageMethod(string message)
			{
				//?$%
				return (Query)_getFactory[message].DynamicInvoke("dd");
			}

			//*******************************************************************************
			//?$%
			private Query getPosts(string message)
			{
				var postQuery =
				from post in db_forum.Posts
				where post.PostID == 1
				select post;
				return new PostQuery(postQuery);
			}

/*
			private void getThreads(string message)
			{
				var threadQuery =
				from thread in db_forum.Threads
				where thread.ThreadID == 1
				select thread;

				foreach (var thread in threadQuery)
				{
					Console.WriteLine("ID={0}, ID={1}", thread.ThreadID, thread.Description);
				}
			}
 */
			//***********************************************************************************

		}
	}

